<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<s:head theme="ajax" debug="true"/>
		<script type="text/javascript">
			
			dojo.event.topic.subscribe("/saveNode", function(data, type, request) {
			    if(type == "load") {
					dojo.byId("n_id").value = "";
					dojo.byId("n_identCode").value = "";
					dojo.byId("n_serialInterface").value = "";
					dojo.byId("n_divisor").value = "";
					dojo.byId("n_timeInterval").value = "";
				}
			});

			dojo.event.topic.subscribe("/editNode", function(data, type, request) {
			    if(type == "before") {
					var id = data.split("_")[1];

					var div = dojo.byId("node_"+id);
					var divs = div.getElementsByTagName("div");

					dojo.byId("n_id").value = id;
					dojo.byId("n_identCode").value = dojo.string.trim(dojo.dom.textContent(divs[0]));
					dojo.byId("n_serialInterface").value = dojo.string.trim(dojo.dom.textContent(divs[1]));
					dojo.byId("n_divisor").value = dojo.string.trim(dojo.dom.textContent(divs[2]));
					dojo.byId("n_timeInterval").value = dojo.string.trim(dojo.dom.textContent(divs[3]));
				}
			});
			
			dojo.event.topic.subscribe("/saveSerialInterface", function(data, type, request) {
				if(type == "load") {
					dojo.byId("si_id").value = "";
					dojo.byId("si_port").value = "";
					dojo.byId("si_baudrate").value = "";
					dojo.byId("si_databits").value = "";
					dojo.byId("si_stopbits").value = "";
					dojo.byId("si_parity").value = "";
					dojo.byId("si_type").value = "";
					dojo.byId("si_active").value = "";
				}
			});

			dojo.event.topic.subscribe("/editSerialInterface", function(data, type, request) {
			    if(type == "before") {
					var id = data.split("_")[1];

					var div = dojo.byId("serialInterface_"+id);
					var divs = div.getElementsByTagName("div");

					dojo.byId("si_id").value = id;
					dojo.byId("si_port").value = dojo.string.trim(dojo.dom.textContent(divs[0]));
					dojo.byId("si_baudrate").value = dojo.string.trim(dojo.dom.textContent(divs[1]));
					dojo.byId("si_databits").value = dojo.string.trim(dojo.dom.textContent(divs[2]));
					dojo.byId("si_stopbits").value = dojo.string.trim(dojo.dom.textContent(divs[3]));
					dojo.byId("si_parity").value = dojo.string.trim(dojo.dom.textContent(divs[4]));
					dojo.byId("si_type").value = dojo.string.trim(dojo.dom.textContent(divs[5]));
					dojo.byId("si_active").value = dojo.string.trim(dojo.dom.textContent(divs[6]));
				}
			});
			
		</script>
</head>
<body>
<s:url id="node" action="node"/>
<s:url id="serialInterface" action="serialInterface"/>
<s:url id="measurement" action="measurement"/>
<s:url id="chart" action="chart"/>
<s:tabbedPanel id="tabbed" theme="ajax" >
  <s:div theme="ajax"  href="%{node}" id="node" label="%{getText('node.main.title')}" listenTopics="/serialInterfacePopulate"/>
  <s:div theme="ajax"  href="%{serialInterface}" id="serialInterface" label="%{getText('serialInterface.main.title')}" />
  <s:div theme="ajax"  href="%{measurement}" id="measurement" label="%{getText('measurement.main.title')}" />
  <s:div theme="ajax"  href="%{chart}" id="chart" label="%{getText('chart.main.title')}" />
</s:tabbedPanel>

</body>
</html>